package com.changgou.order.listener;

import com.alibaba.fastjson.JSON;
import com.changgou.order.config.RabbitMQConfig;
import com.changgou.order.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author: HuangFu
 * @Date: 2020/2/19 15:38
 * @Description: 修改订单服务
 */
@Component
public class OrderPayListener {
    @Autowired
    private OrderService orderService;

    /**
     * 更改订单支付状态监听
     * @param message
     */
    @RabbitListener(queues = RabbitMQConfig.ORDER_PAY)
    public void updatePayStatus(String message){
        System.out.println("接收更改订单支付状态消息");
        Map map = null;
        try {
            map = JSON.parseObject(message, Map.class);
        }catch (Exception e){
            e.printStackTrace();
        }
        if(map == null){
            return;
        }

        orderService.updatePayStatus((String)map.get("orderId"),(String)map.get("transactionId"));
    }


}
